/**
 *
 */
package org.insia.smartposse.manager;

import org.insia.smartposse.manager.iface.IManager;
import org.insia.smartposse.mapping.Categories;
import org.insia.smartposse.mapping.dao.CategoriesDAO;
import org.insia.smartposse.mapping.dao.ProjectsDAO;

/**
 * Manager for Categories
 *
 * @author cmougel
 *
 */
public class CategorieManager implements IManager {

	private final CategoriesDAO _dao = new CategoriesDAO();
	private final Categories _category;

	public CategorieManager(){
		_category = new Categories();
	}

	public CategorieManager(int id){
		_category = _dao.get(id, _dao.getSession());

	}

	public CategorieManager(Categories cat){
		_category = cat;
	}

	public final String getName(){
		return _category.getName();
	}

	public final void setName(String n){
		_category.setName(n);
	}

	/* (non-Javadoc)
	 * @see org.insia.smartposse.manager.iface.IManager#save()
	 */
	public void save() {

		// No NULL in Database
		if (null == _category.getName()){
			_category.setName("");
		}

		_dao.saveOrUpdate(_category);

	}

	/**
	 * @return the category save into manager
	 */
	public Categories getCateory() {
		return _category;
	}

}
